package com.SuanFa.mayukun;

import java.util.Scanner;

public class bbb {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 读取输入的第一行：n, m, p, q
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int p = scanner.nextInt();
        int q = scanner.nextInt();

        // 检查重塑是否可行
        if (n * m != p * q) {
            // 题目可能保证输入合法，这里假设输入合法
        }

        // 读取原矩阵
        int[][] originalMatrix = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                originalMatrix[i][j] = scanner.nextInt();
            }
        }

        // 直接计算新矩阵的位置，不显式创建线性数组
        int[][] reshapedMatrix = new int[p][q];
        for (int k = 0; k < n * m; k++) {
            int i = k / m;       // 原矩阵的行
            int j = k % m;       // 原矩阵的列
            int newI = k / q;    // 新矩阵的行
            int newJ = k % q;    // 新矩阵的列
            reshapedMatrix[newI][newJ] = originalMatrix[i][j];
        }

        // 输出重塑后的矩阵
        for (int i = 0; i < p; i++) {
            for (int j = 0; j < q; j++) {
                System.out.print(reshapedMatrix[i][j]);
                if (j < q - 1) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }

        scanner.close();
    }
}